package com.example.administrator.maizuofilm.recommend.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.bean.NotShow;
import com.example.administrator.maizuofilm.bean.Recommend;

import java.util.List;

/**
 * Created by Administrator on 2016/7/13.
 */
public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.RecommendViewHolder> {
    private List<Recommend.DataBean> filmListBeen;
    private Context context;

    public RecommendAdapter(List<Recommend.DataBean> filmListBeen,Context context) {
        this.filmListBeen = filmListBeen;
        this.context=context;
    }
   private RecommendListener listener;

    public void setListener(RecommendListener listener) {
        this.listener = listener;
    }

    public interface RecommendListener {
    void onImageViewListener(View v,int position);
    void onDetailListener(View v,int position);
    void onLikeListener(View v,int position);

    }


    @Override
    public RecommendViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecommendViewHolder holder = null;
        holder = new RecommendViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recommend, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(RecommendViewHolder holder, int position) {
        holder.textview_grade_movie.setText(filmListBeen.get(position).getGrade());
        holder.textview_name_movie.setText(filmListBeen.get(position).getMovieName());
        holder.textview_type_movie.setText(filmListBeen.get(position).getFilmType());
        holder.tv_count_recommend.setText(filmListBeen.get(position).getLikeCounts());
        Glide.with(context).load(filmListBeen.get(position).getBigPoster()).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return filmListBeen.size();
    }

    class RecommendViewHolder extends RecyclerView.ViewHolder {
        TextView textview_name_movie, textview_type_movie, textview_grade_movie, tv_count_recommend;
        ImageView iv;
        LinearLayout detail,like;

        public RecommendViewHolder(View itemView) {
            super(itemView);
            textview_name_movie = (TextView) itemView.findViewById(R.id.textview_name_movie);
            textview_type_movie = (TextView) itemView.findViewById(R.id.textview_type_movie);
            textview_grade_movie = (TextView) itemView.findViewById(R.id.textview_grade_movie);
            tv_count_recommend = (TextView) itemView.findViewById(R.id.tv_count_recommend);
            iv = (ImageView) itemView.findViewById(R.id.imageview_body_movie);
            detail= (LinearLayout) itemView.findViewById(R.id.layout_detail_recommend);
            like= (LinearLayout) itemView.findViewById(R.id.layout_like_recommend);
            iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener!=null){
                        listener.onImageViewListener(v,getLayoutPosition());
                    }
                }
            });
            detail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener!=null){
                        listener.onDetailListener(v,getLayoutPosition());
                    }
                }
            });
            like.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener!=null){
                        listener.onLikeListener(v,getLayoutPosition());
                    }
                }
            });
        }
    }
}
